<template>
  <div class="bcv-right">
		<div class="bcvr-title">
			<div class="bcvr-left">{{menuChildName}}</div>
			<div class="bcvr-right">首页>{{menuName}}</div>
		</div>
		<div class="bcvr-content" v-for="(item,index) in menuChildContent" :key="index" v-html="item.content">
		</div>
	</div>
</template>

<script>
	import 	News 		from "@/service/news-service.js";
	import 	Menu 		from "@/service/menu-service.js"
	const 	_menu 	= 		new Menu();
	const 	_news 		=	  new News();
	export default {
		name: 'NavRight',
		props:['menuName','menuId'],
		data :function() {
			return {
				menuChildId 			: "",
				menuChildName			: "",
				menuChildContent	: {},
				childMenu					: {}
			}
		},
	  	watch: {
			$route( to , from ){  
				if( this.$route.params.id==null ){
						this.menuChildName		= this.childMenu[0].name;
						this.menChildId				= this.childMenu[0].id;
					}else{
						for(var i = 0;i<this.childMenu.length;i++){
							if( this.childMenu[i].id == this.$route.params.id ){
								this.menuChildName		= this.childMenu[i].name;
								this.menChildId				= this.childMenu[i].id;
							}
						}
					}
			this.findNewsList(this.menChildId);
			}
		},
		created (){
			this.findMenuChild(this.menuId);
		},
		components:{
		},
	  	methods:{
	  	// 这个是通过类型进行查找指定的数据
			findNewsList(id){
				_news.newsList({'type':id,'pageSize':'1','currentPage':'0'}).then((res)=>{
					this.menuChildContent = res.data;
				},(errMsg)=>{
					console.log(errMsg);
				})
			},
			findMenuChild(id){
				_menu.menuList({'pId': id}).then((res)=>{
					this.childMenu 				= res.data;
					if( this.$route.params.id==null ){
						this.menuChildName		= this.childMenu[0].name;
						this.menChildId				= this.childMenu[0].id;
					}else{
						for(var i = 0;i<this.childMenu.length;i++){
							if( this.childMenu[i].id == this.$route.params.id ){
								this.menuChildName		= this.childMenu[i].name;
								this.menChildId				= this.childMenu[i].id;
							}
						}
					}
					this.findNewsList(this.menChildId);
				},(errMsg)=>{
					console.log(errMsg);
				})
			}
	  }
	}
</script>

<style scoped lang="less">
	.bcv-right{
		width: 74%;
		float: left;
		padding: 14px 35px 66px 35px;
		border-left: 1px solid #e6e6e6;
		.bcvr-title{
			width:100%;
			display:table;
			border-bottom: 1px solid #e2e2e2;
			.bcvr-left{
				float: left;
				padding-bottom: 14px;
				border-bottom: 3px solid #C62E25;
			}
			.bcvr-right{
				float: right;
				color: #999;
				font-size:14px;
			}
		}
		.bcvr-content{
			padding-top: 10px;
			color: #666;
		}
	}
</style>